package cn.bdqn.controller;

import cn.bdqn.pojo.VehicleComplaints;
import cn.bdqn.service.VehicleComplaintsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("veh")
public class VehicleComplaintsController {
    @Resource
    VehicleComplaintsService vehicleComplaintsService;
    @RequestMapping("/list")
    public String list(Long brandId, Model model){
        List<VehicleComplaints> list =
                vehicleComplaintsService.selectAll(brandId);
        model.addAttribute("vc",list);
        model.addAttribute("brands",brandId);
        return "list";
    }
    @RequestMapping("/toAdd")
    public String toAdd(){
        return "add";
    }


    @RequestMapping("/add")
    public String add(VehicleComplaints vehicleComplaints){
        int insert = vehicleComplaintsService.insert(vehicleComplaints);
        if (insert>0){
            return "redirect:/veh/list";
        }else{
            return "redirect:/veh/toAdd";
        }
    }
    @ResponseBody
    @RequestMapping("/update")
    public Object update(Long id,Integer status){
        int update = vehicleComplaintsService.update(id,status);
        Map<String,Object> map=new HashMap<>();
        if (update>0){
            map.put("reult",true);
        }else{
            map.put("reult",false);
        }
        return map;
    }
}
